package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyGoodsPay;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyGoodsPayParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyGoodsPayResult;
import cn.stylefeng.guns.sys.modular.system.service.BtyGoodsPayService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 控制器
 *
 * @author jiangge
 * @Date 2021-07-08 11:46:51
 */
@Controller
@RequestMapping("/btyGoodsPayApi")
public class BtyGoodsPayApiController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(BtyGoodsPayApiController.class);
    @Autowired
    private BtyGoodsPayService btyGoodsPayService;


    /**
     * 根据参数 月份、妖码 查询货赔列表
     *
     * @author jiangge
     * @Date 2021-07-08
     */
    @ResponseBody
    @RequestMapping(value = "/findAllData", method = RequestMethod.POST)
    public ResponseData findAllData(BtyGoodsPayParam param) {
        logger.info("货赔查询列表参数：{}", param.toString());
        if (StringUtils.isBlank(param.getMonth())) {
            return ResponseData.error(412, "请求失败，月份参数不能为空");
        }
        if (StringUtils.isBlank(param.getYaoma())) {
            return ResponseData.error(412, "请求失败，妖码参数不能为空");
        }


//        if(CollectionUtil.isEmpty(yaomas)|| StringUtils.isBlank(param.getMonth())){
//            Map<Integer, List<BtyGoodsPayResult>> detail=new HashMap<>();
//            return ResponseData.success(200, "妖码和月份条件为空，返回数据为空", detail);
//        }

        List<BtyGoodsPayResult> detail = this.btyGoodsPayService.findAllData(param);
        return ResponseData.success(detail);
    }

    /**
     * 根据参数 月份、妖码 查询货赔列表
     *
     * @author jiangge
     * @Date 2021-07-08
     */
    @ResponseBody
    @RequestMapping(value = "/findAllPageData", method = RequestMethod.POST)
    public ResponseData findAllPageData(BtyGoodsPayParam param) {
        logger.info("货赔查询列表参数：{}", param.toString());
        if (StringUtils.isBlank(param.getMonth())) {
            return ResponseData.error(412, "请求失败，月份参数不能为空");
        }
        if (StringUtils.isBlank(param.getYaoma())) {
            return ResponseData.error(412, "请求失败，妖码参数不能为空");
        }
        if (param.getLimit() == null) {
            return ResponseData.error(412, "请求失败，分页参数-每页数量为必传，不可为空");
        }
        if (param.getPage() == null) {
            return ResponseData.error(412, "请求失败，分页参数-当前页为必传，不可为空");
        }


        LayuiPageInfo pageInfo = this.btyGoodsPayService.findAllPageData(param);

        // List<BtyGoodsPayResult> detail = this.btyGoodsPayService.findAllData(param);

        return ResponseData.success(pageInfo);
    }

    /**
     * 根据参数 月份、妖码 查询货赔列表
     *
     * @author jiangge
     * @Date 2021-07-08
     */
    @ResponseBody
    @RequestMapping(value = "/submitDatas", method = RequestMethod.POST)
    public ResponseData submitDatas(BtyGoodsPayParam param) {
        logger.info("货赔提交参数：{}", param.toString());
        if (param.getId() == null) {
            return ResponseData.error(412, "提交失败，主键id缺失");
        }
        this.btyGoodsPayService.submitDatas(param);

        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jiangge
     * @Date 2021-07-08
     */
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData detail(BtyGoodsPayParam btyGoodsPayParam) {
        BtyGoodsPay detail = this.btyGoodsPayService.getById(btyGoodsPayParam.getId());
        return ResponseData.success(detail);
    }
}


